//
//  ComprehensiveCell.swift
//  HuaYun
//
//  Created by enghou on 2018/12/10.
//  Copyright © 2018 xyxorigation. All rights reserved.
//

import UIKit

class ComprehensiveCell: UITableViewCell {

    @IBOutlet weak var nameLabel: UILabel!
    
    
    @IBOutlet weak var planIncomeLabel: UILabel!
    @IBOutlet weak var executeIncomeLabel: UILabel!
    @IBOutlet weak var incomeCompletnessLabel: UILabel!
    
    @IBOutlet weak var planCostLabel: UILabel!
    @IBOutlet weak var executeCostLabel: UILabel!
    @IBOutlet weak var costCompletnessLabel: UILabel!
    
    var _model: JSON?
    var model: JSON? {
        set{
            _model = newValue
            nameLabel.text = _model?.contents?["name"]?.rawString()
            
            let incomeexec = _model?.contents?["planExecuteIncome"]?.int ?? 0
            self.executeIncomeLabel.text = String(incomeexec / 1000000).rmbformat
            let incomeplan = _model?.contents?["planBudgetIncome"]?.int ?? 0
            self.planIncomeLabel.text = String(incomeplan / 1000000).rmbformat
            if incomeplan > 0 {
                let ratio = Double(incomeexec * 100) / Double(incomeplan)
                self.incomeCompletnessLabel.text = String(format: "%.2f", ratio) + "%"
            } else {
                self.incomeCompletnessLabel.text = "0%"
            }
            let planExecuteCost = _model?.contents?["planExecuteCost"]?.int ?? 0
            self.executeCostLabel.text = String(planExecuteCost / 1000000).rmbformat
            let planBudgetCost = _model?.contents?["planBudgetCost"]?.int ?? 0
            self.planCostLabel.text = String(planBudgetCost / 1000000).rmbformat
            if planBudgetCost > 0 {
                let ratio = Double(planExecuteCost * 100) / Double(planBudgetCost)
                self.costCompletnessLabel.text = String(format: "%.2f", ratio) + "%"
            } else {
                self.costCompletnessLabel.text = "0%"
            }
        }
        get{
            return _model
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
